package 代码随想录.链表;


 class ListNode {
    int val;
    ListNode next = null;

    ListNode(int val) {
        this.val = val;
    }
}
public class 反转链表 {
    /**JZ24反转链表
     * 206. 反转链表
     * https://leetcode.cn/problems/reverse-linked-list/
     * 给你单链表的头节点 head ，请你反转链表，并返回反转后的链表。
     */
    public ListNode reverseList(ListNode head) {
        ListNode newhead = null;
        while(head!=null){
            ListNode p = head.next;
            head.next = newhead;
            newhead = head;
            head = p;
        }
        return newhead;
    }

}
